package peer;

import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;

public abstract class ConnectionManager implements Runnable {
	
	ConcurrentHashMap<String, Connection> connectionMap;
	static final int MIN_CONNECTIONS = 5; // Minimum number of connections to avoid looking for more
	static final int SLEEP_TIME = 10000; // Number of milliseconds between polling for 
	
	public ConnectionManager(ConcurrentHashMap<String, Connection> connectionMap) {
		this.connectionMap = connectionMap;
	}
	
	abstract void discoverNewConnection();
/*
	@Override
	public void run() {	
		while (true) {
			if ( connectionMap.size() < MIN_CONNECTIONS) {
				if (connectionMap.isEmpty() ) {
					discoverNewConnection();
				}
				for (String currentID: connectionMap.keySet()) {
					try {
						connectionMap.get(currentID).writeObject(MessageFactory.newGetConnectionsMessage());
					} catch (IOException e) {
						connectionMap.get(currentID).kill();
						connectionMap.remove(currentID);
					}
				}
			}
			try {
				Thread.sleep(SLEEP_TIME);
			} catch (InterruptedException e) {
				// Need to get more connections again.
			}
		}
	}*/
}
